﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.System;

namespace TranshumanityNet.Common
{ 
    public class Tools
    {
        public static String SettingsContainerName = "SettingsMaster";

        public static async void NavigateTo(String ThisUrl)
        {
            //Frame.Navigate(typeof(ParchmentApps)); ?
            await Launcher.LaunchUriAsync(new Uri(ThisUrl));
        }

        public static String GetSetting(String ValueKey)
        {
            ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;

            if (localSettings.Containers.ContainsKey(SettingsContainerName))
            {
                if (localSettings.Containers[SettingsContainerName].Containers.ContainsKey(ValueKey))
                {
                    return localSettings.Containers[SettingsContainerName].Values[ValueKey].ToString();
                }
                else
                {
                    return String.Empty;
                }

            }
            else
            {
                return String.Empty;
            }
        }

        public static void SaveSetting(String ValueKey, String Value)
        {
            ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;

            if (!(localSettings.Containers.ContainsKey(SettingsContainerName)))
            {
                localSettings.CreateContainer(SettingsContainerName, ApplicationDataCreateDisposition.Always);
            }

            localSettings.Containers[SettingsContainerName].Values[ValueKey] = Value;
        }
    }
}
